In [1]:
x=5
j=2

In [2]:
print(j)


2

In [4]:
import numpy as np

In [5]:
import matplotlib as plt

In [6]:
plt.plot(1,2)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-ca62d03991ac> in <module>()
----> 1 plt.plot(1,2)

AttributeError: module 'matplotlib' has no attribute 'plot'

In [11]:
np.arange(4,10, .1)


Out[11]:
array([ 4. ,  4.1,  4.2,  4.3,  4.4,  4.5,  4.6,  4.7,  4.8,  4.9,  5. ,
        5.1,  5.2,  5.3,  5.4,  5.5,  5.6,  5.7,  5.8,  5.9,  6. ,  6.1,
        6.2,  6.3,  6.4,  6.5,  6.6,  6.7,  6.8,  6.9,  7. ,  7.1,  7.2,
        7.3,  7.4,  7.5,  7.6,  7.7,  7.8,  7.9,  8. ,  8.1,  8.2,  8.3,
        8.4,  8.5,  8.6,  8.7,  8.8,  8.9,  9. ,  9.1,  9.2,  9.3,  9.4,
        9.5,  9.6,  9.7,  9.8,  9.9])

In [12]:
ds = np.arange(1,10,2)

In [13]:
ds.ndim


Out[13]:
1

In [14]:
ds


Out[14]:
array([1, 3, 5, 7, 9])

In [15]:
ds.shape


Out[15]:
(5,)

In [16]:
ds.size


Out[16]:
5

In [17]:
ds.dtype


Out[17]:
dtype('int64')

In [18]:
ds.itemsize


Out[18]:
8

In [20]:
list(ds.data)


Out[20]:
[1, 3, 5, 7, 9]

In [21]:
x=ds.data
list(x)


Out[21]:
[1, 3, 5, 7, 9]

In [22]:
ds.data


Out[22]:
<memory at 0x1052a91c8>

In [23]:
ds


Out[23]:
array([1, 3, 5, 7, 9])

In [24]:
ds.size * ds.itemsize


Out[24]:
40

In [25]:
np.array([1,2,3,4,5])


Out[25]:
array([1, 2, 3, 4, 5])

In [26]:
np.zeros((3,3))


Out[26]:
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.]])

In [27]:
np.linespace(0,5, num=10)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-27-9f3d19055749> in <module>()
----> 1 np.linespace(0,5, num=10)

AttributeError: module 'numpy' has no attribute 'linespace'

In [31]:
np.linspace(1,2, num=20)


Out[31]:
array([ 1.        ,  1.05263158,  1.10526316,  1.15789474,  1.21052632,
        1.26315789,  1.31578947,  1.36842105,  1.42105263,  1.47368421,
        1.52631579,  1.57894737,  1.63157895,  1.68421053,  1.73684211,
        1.78947368,  1.84210526,  1.89473684,  1.94736842,  2.        ])

In [32]:
np.random.random((0,100))


Out[32]:
array([], shape=(0, 100), dtype=float64)

In [38]:
# This gives you an M by N matrix with random number

random_array = np.random.random((1,10))

In [46]:
np.max(random_array)


Out[46]:
0.89957642887485278

In [40]:
random_array


Out[40]:
array([[ 0.52216224,  0.22277595,  0.89724093,  0.72307035,  0.26139546,
         0.89957643,  0.55556312,  0.53111782,  0.08359911,  0.47197461]])

In [47]:
np.min(random_array)


Out[47]:
0.083599105159251841

In [48]:
np.mean(random_array)


Out[48]:
0.51684760273888852

In [49]:
np.median(random_array)


Out[49]:
0.52664002941518839

In [50]:
np.std(random_array)


Out[50]:
0.26017125394146845

In [51]:
np.sum(random_array)


Out[51]:
5.168476027388885

In [52]:
np.reshape(random_array, (2,5))


Out[52]:
array([[ 0.52216224,  0.22277595,  0.89724093,  0.72307035,  0.26139546],
       [ 0.89957643,  0.55556312,  0.53111782,  0.08359911,  0.47197461]])

In [53]:
random_array


Out[53]:
array([[ 0.52216224,  0.22277595,  0.89724093,  0.72307035,  0.26139546,
         0.89957643,  0.55556312,  0.53111782,  0.08359911,  0.47197461]])

In [55]:
np.ravel(random_array)


Out[55]:
array([ 0.52216224,  0.22277595,  0.89724093,  0.72307035,  0.26139546,
        0.89957643,  0.55556312,  0.53111782,  0.08359911,  0.47197461])

In [57]:
import matplotlib.pyplot as plt

In [58]:
x= [0,1,2]
y= [0,1,4]
fig = plt.figure()
axes = fig.add_subplot(111)

axes.plot(x,y)
plt.show()



In [78]:
x_highres = np.linspace(0, 2, 20)
y_highres = x_highres ** 2

fig = plt.figure()
axes = fig.add_subplot(111)

axes.set_title("This is a title")
axes.plot(x, y, color="black", linestyle="dashed", marker='o')
axes.plot(x_highres, y_highres, color="red")
axes.grid()
plt.show()



In [65]:
x_highres


Out[65]:
array([ 0.        ,  0.10526316,  0.21052632,  0.31578947,  0.42105263,
        0.52631579,  0.63157895,  0.73684211,  0.84210526,  0.94736842,
        1.05263158,  1.15789474,  1.26315789,  1.36842105,  1.47368421,
        1.57894737,  1.68421053,  1.78947368,  1.89473684,  2.        ])

In [79]:
x_highres = np.linspace(0, 2, 20)
y_highres = x_highres ** 2

fig = plt.figure()
axes = fig.add_subplot(111)

axes.set_title("$y=x^2$")
axes.plot(x, y, color="black", linestyle="dashed", marker='o')
axes.plot(x_highres, y_highres, color="red")
axes.set_xlabel('x')
axes.set_ylabel('y')
axes.grid()
plt.show()


Increase plot res


In [84]:
x_highres = np.linspace(0, 2, 20)
y_highres = x_highres ** 2

fig = plt.figure(figsize=(12, 12))
axes = fig.add_subplot(111)

axes.set_title("$y=x^2$")
axes.plot(x, y, color="black", linestyle="dashed", marker='o')
axes.plot(x_highres, y_highres, color="red")
axes.set_xlabel('x')
axes.set_ylabel('y')
axes.grid()
plt.show()



In [93]:
noise = np.random.random((128,128)) * 100

In [94]:
noise


Out[94]:
array([[ 67.59827691,  79.01678075,  82.92539187, ...,  18.0435834 ,
         94.88347818,  30.0306182 ],
       [ 50.90050849,  92.28525396,  15.85638667, ...,  16.67926362,
         96.11633462,  15.625324  ],
       [  4.44529969,  57.33444302,  91.35617427, ...,  44.11012294,
         56.8666792 ,  96.2611924 ],
       ..., 
       [ 52.95802582,  90.57693625,  19.87927739, ...,  83.09961831,
         79.71295724,  82.18878096],
       [ 76.50465613,  59.21014488,  50.44584671, ...,  86.85802824,
          2.84931   ,  95.3452103 ],
       [ 69.13329822,   9.39090201,  24.24135651, ...,  95.31846117,
         50.92633108,  63.67386144]])

In [95]:
plt.imshow(noise)
plt.colorbar()
plt.show()



In [96]:
plt.imshow(noise, cmap=plt.cm.gray)
plt.colorbar()
plt.show()



In [100]:
plt.imshow(noise, cmap=plt.cm.Paired)
plt.colorbar()
plt.show()



In [ ]: